package com.lt.bcra.controller.questionnaire;


import com.lt.bcra.entity.vo.QuestionnaireInfoVo;
import com.lt.bcra.exception.BaseException;
import com.lt.bcra.service.BcraQuestionnaireResponseService;
import com.lt.bcra.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 回收问卷表 前端控制器
 * </p>
 *
 * @author LuoTian
 * @since 2022-05-25
 */
@Api(tags = "填写问卷回收表")
@CrossOrigin //跨域可以前端配置
@RestController
@RequestMapping("bcra/bcraQuestionnaireResponse")
public class BcraQuestionnaireResponseController {

    private static Logger log = LoggerFactory.getLogger(BcraQuestionnaireResponseController.class);

    @Autowired
    private BcraQuestionnaireResponseService bcraQuestionnaireResponseService;


    @PostMapping("/saveNewQues/{phone}/{name}")
    @ApiOperation("保存一份新问卷")
    @ApiParam(value = "")
    public ResultData saveNewQues(@RequestBody QuestionnaireInfoVo questionnaireInfoVo,
                                  @PathVariable String phone,
                                  @PathVariable String name) throws BaseException {
        if (log.isDebugEnabled()) log.debug("保存一份新问卷 BcraQuestionnaireResponseController");

        return bcraQuestionnaireResponseService.createNewQues(questionnaireInfoVo, phone, name);
    }

    @PostMapping("/submitQues/{questionnaireCode}")
    @ApiOperation("提交新问卷")
    @ApiParam(value = "问卷编号")
    public ResultData submitQues(@PathVariable String questionnaireCode){
        if (log.isDebugEnabled()) log.debug("提交新问卷 BcraQuestionnaireResponseController");

        return bcraQuestionnaireResponseService.updateState(questionnaireCode);
    }

    @DeleteMapping("/deleteQues/{questionnaireCode}")
    @ApiOperation("删除问卷")
    @ApiParam(value = "问卷编号")
    public ResultData deleteQues(@PathVariable String questionnaireCode){
        if (log.isDebugEnabled()) log.debug("删除问卷 BcraQuestionnaireResponseController");

        return bcraQuestionnaireResponseService.deleteQues(questionnaireCode);
    }
    @GetMapping("/getQues/{questionnaireCode}")
    @ApiOperation("查看问卷")
    @ApiParam(value = "问卷编号")
    public ResultData list(@PathVariable String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("查看问卷 BcraPhysiologicalFactorsController");

        return bcraQuestionnaireResponseService.selectByQuesCode(questionnaireCode);
    }
}

